<template>
    <div>
      <!-- <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true"  label-width="68px">
        <el-form-item label="时间区域" prop="projectId">
          <el-input
            v-model="dateRange"
            placeholder="请输入"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form> -->
      <el-table v-loading="loading" :data="list" border>
        <el-table-column label="类别" align="center" prop="commodityTypeName" />
        <el-table-column label="公司库存" align="center">
          <el-table-column label="库存数量" align="center" prop="stockNumber" />
          <el-table-column label="库存金额" align="center" prop="stockMoney" >
              <template slot-scope="scope">
                {{toMoney(scope.row.stockMoney)}}
              </template>
            </el-table-column>
        </el-table-column>
        <el-table-column label="项目库存" align="center">
          <el-table-column label="库存数量" align="center" prop="projectNumber" />
          <el-table-column label="库存金额" align="center" prop="projectMoney" >
            <template slot-scope="scope">
              {{toMoney(scope.row.projectMoney)}}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="个人库存" align="center">
          <el-table-column label="库存数量" align="center" prop="peopleNumber" />
          <el-table-column label="库存金额" align="center" prop="peopleMoney" >
            <template slot-scope="scope">
              {{toMoney(scope.row.peopleMoney)}}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="handleView(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 查看类别明细 -->
      <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body>
          <el-form :model="queryDetailsParams" ref="queryDetailsForm" size="mini" :inline="true"  label-width="68px">
            <el-form-item label="商品编号" prop="commodityNo">
              <el-input v-model="queryDetailsParams.commodityNo" placeholder="请输入商品编号" clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="商品名称" prop="commodityName">
              <el-input v-model="queryDetailsParams.commodityName" placeholder="请输入商品名称" clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleDetailsQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetDetailsQuery">重置</el-button>
            </el-form-item>
          </el-form>
          <el-table v-loading="loading" :data="commodityList" border>
              <el-table-column label="商品编号" align="center" prop="commodityNo" />
              <el-table-column label="商品名称" align="center" prop="commodityName" />
              <el-table-column label="商品规格" align="center" prop="commoditySpec" />
              <el-table-column label="商品品牌" align="center" prop="commodityBrand" />
              <el-table-column label="公司库存" align="center">
                <el-table-column label="库存数量" align="center" prop="stockNumber" />
                <el-table-column label="库存金额" align="center" prop="stockMoney" >
                    <template slot-scope="scope">
                      {{toMoney(scope.row.stockMoney)}}
                    </template>
                  </el-table-column>
              </el-table-column>
              <el-table-column label="项目库存" align="center">
                <el-table-column label="库存数量" align="center" prop="projectNumber" />
                <el-table-column label="库存金额" align="center" prop="projectMoney" >
                  <template slot-scope="scope">
                    {{toMoney(scope.row.projectMoney)}}
                  </template>
                </el-table-column>
              </el-table-column>
              <el-table-column label="个人库存" align="center">
                <el-table-column label="库存数量" align="center" prop="peopleNumber" />
                <el-table-column label="库存金额" align="center" prop="peopleMoney" >
                  <template slot-scope="scope">
                    {{toMoney(scope.row.peopleMoney)}}
                  </template>
                </el-table-column>
              </el-table-column>
          </el-table>
      </el-dialog>
    </div>
  </template>

  <script>
  import { commodityTypeStatistics,commodityTypeDetailsList } from '@/api/cld/materialStatistics'
  export default {
    name: "categoryStatistics",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 表格数据
        list: [],
        commodityList: [],
        dateRange: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 50,
        },
        // 查询参数
        queryDetailsParams:{
          commodityTypeId:null,
          commodityNo:null,
          commodityName:null,
        },
        open: false,
        title: '',
      };
    },
    created() {
      this.getList();
    },
    methods: {
      getList() {
        commodityTypeStatistics(
          this.addDateRange(this.queryParams, this.dateRange)
        ).then(response => {
          this.list = response.rows;
          this.total = response.total;
          this.loading = false;
        })
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 搜索按钮操作 */
      handleDetailsQuery() {
        this.getDetailsList();
      },
      /** 重置按钮操作 */
      resetDetailsQuery() {
        this.resetForm("queryDetailsForm");
        this.handleDetailsQuery();
      },
      // 查看类别明细
      handleView(row){
        this.queryDetailsParams.commodityTypeId = row.commodityTypeId;
        commodityTypeDetailsList({
          commodityTypeId: row.commodityTypeId
        }).then( res => {
          this.title = row.commodityTypeName;
          this.commodityList = res.data;
          this.open = true;
        })
      },
      getDetailsList(){
        commodityTypeDetailsList(this.queryDetailsParams).then( res => {
          this.commodityList = res.data;
        })
      }
    }
  };
  </script>
